package com.nmsl.system.medical_temp.service.impl;

import java.util.Collections;
import java.util.List;

import com.nmsl.system.medical_temp.domain.MedicalHistory;
import com.nmsl.system.medical_temp.mapper.MedicalHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nmsl.system.medical_temp.mapper.MedicalTemplateMapper;
import com.nmsl.system.medical_temp.domain.MedicalTemplate;
import com.nmsl.system.medical_temp.service.IMedicalTemplateService;

/**
 * 病例模板Service业务层处理
 * 
 * @author gmh
 * @date 2025-02-14
 */
@Service
public class MedicalTemplateServiceImpl implements IMedicalTemplateService 
{
    @Autowired
    private MedicalTemplateMapper medicalTemplateMapper;
    @Autowired
    private MedicalHistoryMapper medicalHistoryMapper;

    /**
     * 查询病例模板
     * 
     * @param id 病例模板主键
     * @return 病例模板
     */
    @Override
    public MedicalTemplate selectMedicalTemplateById(Long id)
    {
        return medicalTemplateMapper.selectMedicalTemplateById(id);
    }

    /**
     * 查询病例模板列表
     * 
     * @param medicalTemplate 病例模板
     * @return 病例模板
     */
    @Override
    public List<MedicalTemplate> selectMedicalTemplateList(MedicalTemplate medicalTemplate)
    {
        return medicalTemplateMapper.selectMedicalTemplateList(medicalTemplate);
    }

    /**
     * 新增病例模板
     * 
     * @param medicalTemplate 病例模板
     * @return 结果
     */
    @Override
    public int insertMedicalTemplate(MedicalTemplate medicalTemplate)
    {
        return medicalTemplateMapper.insertMedicalTemplate(medicalTemplate);
    }

    /**
     * 修改病例模板
     * 
     * @param medicalTemplate 病例模板
     * @return 结果
     */
    @Override
    public int updateMedicalTemplate(MedicalTemplate medicalTemplate)
    {
        return medicalTemplateMapper.updateMedicalTemplate(medicalTemplate);
    }

    /**
     * 批量删除病例模板
     * 
     * @param ids 需要删除的病例模板主键
     * @return 结果
     */
    @Override
    public int deleteMedicalTemplateByIds(Long[] ids)
    {
        for (Long id : ids) {
            medicalTemplateMapper.selectMedicalTemplateById(id);
            medicalHistoryMapper.deleteMedicalHistory(id);
        }
        return medicalTemplateMapper.deleteMedicalTemplateByIds(ids);

    }

    /**
     * 删除病例模板信息
     * 
     * @param id 病例模板主键
     * @return 结果
     */
    @Override
    public int deleteMedicalTemplateById(Long id)
    {

        return medicalTemplateMapper.deleteMedicalTemplateById(id);
    }


    @Override
    public long selectMedicalHistoryId(Long id) {
        return medicalTemplateMapper.selectMedicalHistoryId(id);
    }

    @Override
    public List<MedicalHistory> selectHistoryByTempId(Long id) {
        return medicalTemplateMapper.selectHistoryByTempId(id);
    }
}
